/** 车险必填字段校验提示 2015年由“必填字段”修改为“请您输入XXX。” */
//车牌
jQuery.validator.addMethod("licenseRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入车牌。");

//车架号
jQuery.validator.addMethod("vinNoRequired", function(value, element) {
	var defaultValue = ["如：LS4AAB3D8BA022393"];
	//默认值判断
	for(var d in defaultValue){
		if(value==defaultValue[d]){
			return false;
		}
	}
	if(value==""||value.length!=17){
		return false;
	}
	return true;
}, "2002年后车架号为17位哦");

//车架校验QIO
jQuery.validator.addMethod("V_vinCheck_QIO", function(value, element) {
	if (value == "") {
		return true;
	}
	var reg2=/(^[^IOQ]+$)/;
	return this.optional(element) || (reg2.test(value) && value.length == 17);
}, "车架号首字不包含Q/I/O哦");

//发动机号
jQuery.validator.addMethod("motorNoRequired", function(value, element) {
	var defaultValue = ["如：B69C5"];
	//默认值判断
	for(var d in defaultValue){
		if(value==defaultValue[d]){
			return false;
		}
	}
	if(value==""){
		return false;
	}
	return true;
}, "请您输入发动机号。");

//车辆型号
jQuery.validator.addMethod("modelRequired", function(value, element) {
	var defaultValue = ["如：别克SGM7150ATA轿车"];
	//默认值判断
	for(var d in defaultValue){
		if(value==defaultValue[d]){
			return false;
		}
	}
	if(value==""){
		return false;
	}
	return true;
}, "请参考行驶证型号填写。");

//车主姓名
jQuery.validator.addMethod("carOwnerRequired", function(value, element) {
	var defaultValue = ["请填写行驶证上的车主姓名"];
	//默认值判断
	for(var d in defaultValue){
		if(value==defaultValue[d]){
			return false;
		}
	}
	if(value==""){
		return false;
	}
	return true;
}, "请您输入车主姓名。");

//证件号
jQuery.validator.addMethod("identityNoRequired", function(value, element) {
	var defaultValue = ["请填写行驶证上的车主身份证"];
	//默认值判断
	for(var d in defaultValue){
		if(value==defaultValue[d]){
			return false;
		}
	}
//	if(value==""||value.length<15||(value.length>15&&value.length<18)){
//		return false;
//	}
	return true;
}, "请您输入证件号");

//车主身份证校验
jQuery.validator.addMethod("V_idCheck2", function(value, element) {
	if(value==""){
		return false;
	}
	if(value.length==18){
		value = value.substr(0,17);
	}
	var reg = /^[0-9]*$/;
	return this.optional(element) || reg.test(value);
}, "身份证号不能含非法字符哦");

//配送地址 非空校验
jQuery.validator.addMethod("V_receiverAddress", function(value, element) {
	if(value==""||value.length<4){
		return false;
	}
	return true;
}, "配送地址过短，请重新输入");

// 座位数
jQuery.validator.addMethod("seatRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入座位数。");

//过户日期
jQuery.validator.addMethod("transferDateRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入过户日期。");

//起保日期
jQuery.validator.addMethod("effectDateRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入起保日期。");

//初等日期
jQuery.validator.addMethod("registerDateRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入车辆注册日期。");

//初等日期
jQuery.validator.addMethod("certificateDateRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入购车发票日期。");

//姓名
jQuery.validator.addMethod("nameRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入姓名。");

//性别
jQuery.validator.addMethod("sexRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入性别。");

//驾驶证号
jQuery.validator.addMethod("cardRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入驾驶证号。");

//领证日期
jQuery.validator.addMethod("firstDateRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入领证日期。");

//证件类型
jQuery.validator.addMethod("idTypeRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入证件类型。");

//手机
jQuery.validator.addMethod("mobieRequired", function(value, element) {
	if($.trim(value)==""||$.trim(value).length!=11){
		return false;
	}
	return true;
}, "手机号必须为11位哦"); 


/** opMobilePhone与opCheckMail是iframe迁入的时候使用的，能使悬浮框和.error交替显示  */
jQuery.validator.addMethod("opMobilePhone",function(value,element){
	var s = value.substr(0,3);
	var condition =  /^(13|14|15|17|18)\d{9}$/.test(value) && s != '170' && s != '171' ;
	if(!(this.optional(element) || condition)){
		removeTips();
	}
	return this.optional(element) || condition;
},"手机号无效或虚拟手机号");

jQuery.validator.addMethod("opCheckMail",function(value,element){
	if(!(this.optional(element) || /^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z-]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]|net|NET|asia|ASIA|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT|cn|CN|cc|CC)$/.test(value))){
		removeTips();
	}
	return this.optional(element) || /^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z-]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]|net|NET|asia|ASIA|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT|cn|CN|cc|CC)$/.test(value);
},"请按照A@B.com格式输入");

//收件人
jQuery.validator.addMethod("receiverRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入收件人。"); 

//联系方式
jQuery.validator.addMethod("receiverMobileRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入联系方式。"); 

//配送时间
jQuery.validator.addMethod("disTimeRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入配送时间。"); 

//答案
jQuery.validator.addMethod("answerRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入答案。"); 

//行驶区域
jQuery.validator.addMethod("addressRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入行驶区域。"); 

//车辆配置型号
jQuery.validator.addMethod("configRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入车辆配置型号。"); 

//车价
jQuery.validator.addMethod("carPricePequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入车价。");

//燃料种类
jQuery.validator.addMethod("fuelTypeRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入燃料种类。");

//税款所属期
jQuery.validator.addMethod("taxPeriodRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入税款所属期。");

//居住地址
jQuery.validator.addMethod("taxAddressRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入居住地址。");

//通讯地址
jQuery.validator.addMethod("postRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入通讯地址。");

//纳税人识别号
jQuery.validator.addMethod("taxPayerIdentificationRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入纳税人识别号。");

//邮政编码
jQuery.validator.addMethod("postCodeRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入邮政编码。");

//电话
jQuery.validator.addMethod("phoneRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入电话。");

//邮箱
jQuery.validator.addMethod("mailRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入邮箱。");

//收件地址
jQuery.validator.addMethod("psAddressRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入收件地址。");

//地址
jQuery.validator.addMethod("addressRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入地址。");

//验证身份证
var showErrMsg="身份证号不正确，请重新输入";
jQuery.validator.addMethod("checkIdcard", function(value, element) {
	var idcard = value;
	if(idcard==""){
		return true;
	}
	var regex1 = /^[1-9][0-7]\d{4}((([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})(((0[13578]|1[02])(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)(0[1-9]|[12][0-9]|30))|(02(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))0229))\d{3}(\d|X|x)?$/;
	
	/*身份号码位数及格式检验*/
	switch (idcard.length) {
	  case 15:
		if ( (parseInt(idcard.substr(6,2))+1900) % 4 == 0 || ((parseInt(idcard.substr(6,2))+1900) % 100 == 0 && (parseInt(idcard.substr(6,2))+1900) % 4 == 0 )){
			var regex2 = /^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;//测试出生日期的合法性
		} else {
			var regex2 = /^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;//测试出生日期的合法性
		}

		if(regex2.test(idcard)) 
			return true;
		else 
			return false;
		break; 
	  case 18:
	 	 if(regex1.test(idcard)){
			var S = (parseInt(idcard.charAt(0)) + parseInt(idcard.charAt(10))) * 7 + 
                (parseInt(idcard.charAt(1)) + parseInt(idcard.charAt(11))) * 9 + 
                (parseInt(idcard.charAt(2)) + parseInt(idcard.charAt(12))) * 10 + 
                (parseInt(idcard.charAt(3)) + parseInt(idcard.charAt(13))) * 5 + 
                (parseInt(idcard.charAt(4)) + parseInt(idcard.charAt(14))) * 8 + 
                (parseInt(idcard.charAt(5)) + parseInt(idcard.charAt(15))) * 4 + 
                (parseInt(idcard.charAt(6)) + parseInt(idcard.charAt(16))) * 2 + 
                parseInt(idcard.charAt(7)) * 1 + 
                parseInt(idcard.charAt(8)) * 6 + 
                parseInt(idcard.charAt(9)) * 3;
            var Y = S % 11;
			var M = "F";
			var JYM = "10X98765432";
			M = JYM.substr(Y, 1);
			/*判断校验位*/
			if (M == idcard.charAt(17).toUpperCase()) {
	     			//alert(Errors[0]+"18"); 
				return true;
			} else {
				//alert(Errors[3]);
				//showErrMsg = Errors[3];
				return false;
			}
		}else{
			return false;
		}
		break;
	  default:
	  	//alert(Errors[1]);
		//showErrMsg = Errors[1];
		return false;
	}
}, jQuery.validator.format(showErrMsg));

//被保险人生日
jQuery.validator.addMethod("birthDateRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "请您输入被保险人生日。");

jQuery.validator.addMethod("V_autoBankRequired", function(value, element) {
	if(value==""){
		return false;
	}
	return true;
}, "autoBank");
jQuery.validator.addMethod("V_autoBankIdCheck", function(value, element) {
	var idcard = value;
	if(idcard==""){
		return true;
	}
	var regex1 = /^[1-9][0-7]\d{4}((([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})(((0[13578]|1[02])(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)(0[1-9]|[12][0-9]|30))|(02(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))0229))\d{3}(\d|X|x)?$/;
	
	/*身份号码位数及格式检验*/
	switch (idcard.length) {
	  case 15:
		if ( (parseInt(idcard.substr(6,2))+1900) % 4 == 0 || ((parseInt(idcard.substr(6,2))+1900) % 100 == 0 && (parseInt(idcard.substr(6,2))+1900) % 4 == 0 )){
			var regex2 = /^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;//测试出生日期的合法性
		} else {
			var regex2 = /^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;//测试出生日期的合法性
		}

		if(regex2.test(idcard)) 
			return true;
		else 
			return false;
		break; 
	  case 18:
	 	 if(regex1.test(idcard)){
			var S = (parseInt(idcard.charAt(0)) + parseInt(idcard.charAt(10))) * 7 + 
                (parseInt(idcard.charAt(1)) + parseInt(idcard.charAt(11))) * 9 + 
                (parseInt(idcard.charAt(2)) + parseInt(idcard.charAt(12))) * 10 + 
                (parseInt(idcard.charAt(3)) + parseInt(idcard.charAt(13))) * 5 + 
                (parseInt(idcard.charAt(4)) + parseInt(idcard.charAt(14))) * 8 + 
                (parseInt(idcard.charAt(5)) + parseInt(idcard.charAt(15))) * 4 + 
                (parseInt(idcard.charAt(6)) + parseInt(idcard.charAt(16))) * 2 + 
                parseInt(idcard.charAt(7)) * 1 + 
                parseInt(idcard.charAt(8)) * 6 + 
                parseInt(idcard.charAt(9)) * 3;
            var Y = S % 11;
			var M = "F";
			var JYM = "10X98765432";
			M = JYM.substr(Y, 1);
			/*判断校验位*/
			if (M == idcard.charAt(17).toUpperCase()) {
	     			//alert(Errors[0]+"18"); 
				return true;
			} else {
				//alert(Errors[3]);
				//showErrMsg = Errors[3];
				return false;
			}
		}else{
			return false;
		}
		break;
	  default:
	  	//alert(Errors[1]);
		//showErrMsg = Errors[1];
		return false;
	}
},"autoBank");
jQuery.validator.addMethod("V_autoBankphoneCheck", function(value, element) {
	var s = value.substr(0,3);
	var condition =  /^(13|14|15|17|18)\d{9}$/.test(value) && s != '170' && s != '171';
	return this.optional(element) || condition;
}, "autoBank");
jQuery.validator.addMethod("checkFidType", function(value, element) {
	var reg = /^[A-Za-z0-9]+$/;//匹配字母和数字
    return this.optional(element) || reg.test(value);
}, "请输入正确的字母和数字");